
import 'dart:io';

import 'package:baselib/utils/gallery_camera_pick_util.dart';
import 'package:baselib/utils/image_util.dart';
import 'package:baselib/utils/keyboard_util.dart';
import 'package:baselib/utils/load_util.dart';
import 'package:baselib/utils/log_util.dart';
import 'package:baselib/utils/md5_util.dart';
import 'package:baselib/utils/navigator_util.dart';
import 'package:baselib/utils/px_base_util.dart';
import 'package:baselib/utils/toast_util.dart';
import 'package:baselib/widgets/dialog_util.dart';
import 'package:flutter/material.dart';
import 'package:framelib/base/base_view_model.dart';
import 'package:framelib/config/api_config.dart';
import 'package:framelib/config/route_config.dart';
import 'package:framelib/net/baseentity.dart';
import 'package:framelib/utils/oss_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:module_business/module_chat/model/gift_entity.dart';
import 'package:module_business/module_chat/service/module_chat_service.dart';
import 'package:module_business/module_comm/model/user_entity.dart';
import 'package:module_business/module_index/model/voice_chat_tag_entity.dart';
import 'package:module_business/module_index/service/module_index_service.dart';
import 'package:module_business/module_index/view/create_voice_room_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_my/service/module_my_service.dart';

class RoomGiftsBottomSheetViewModel extends BaseViewModel<ModuleChatService>{

  ModuleChatService moduleChatService;
  ModuleMyService moduleMyService;
  String yxRoomId;
  int roomId;
  List<UserEntity> defaultPersons;
  //礼物列表
  List<GiftEntity> giftsDatas = [];
  TextEditingController numTextEditingController = TextEditingController(text: '1');
  RoomGiftsBottomSheetViewModel({this.yxRoomId,this.roomId,this.defaultPersons});

  Rx<List<UserEntity>> selectedPersons = Rx<List<UserEntity>>([]);

  @override
  ModuleChatService createService(){
    moduleMyService = ModuleMyService();
    return moduleChatService = ModuleChatService();
  }

  @override
  void onInit() {
    if((defaultPersons??[]).isNotEmpty)selectedPersons.value=(defaultPersons??[]);
    super.onInit();
    getGiftsList();
  }
  @override
  void onClose() {
    if(numTextEditingController!=null)numTextEditingController.dispose();
    super.onClose();
  }
  void getGiftsList() async{
    Map<String,dynamic> upData={};
    BaseEntity baseEntity = await moduleMyService.api_voicechat_gift_list(parmsMap: upData);
    if(baseEntity?.code == ApiConfig.SUCCESS_CODE){
      giftsDatas = baseEntity?.result??[];
    }
    update();
  }

  onPenAll() {
    LogUtil.d('RoomUpmicPersonViewModel-->yxRoomId=$yxRoomId,roomId=$roomId');
    NavigatorUtil.pushByName(RouteConfig.roomUpmicPersonlistPage,
      arguments: {
        'yxRoomId':yxRoomId,
        'roomId':roomId,
        'defaultPersonIds': (selectedPersons.value??[]).map((e) => '${e?.userId}').toList()
      },
      resultFunc: (value){
        if((value!=null)&&(value is Map)&&(value['result']=='ok')){
          selectedPersons.value = value['selectedPersons']??[];
        }
      }
    );
  }
}
